<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">

<div id="app">
    <div class="content-header">
        <h1>系统管理
            <small>角色管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统管理</el-breadcrumb-item>
            <el-breadcrumb-item>角色管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">

            <div class="filter-container">
                <el-input placeholder="角色名" style="width: 200px;" class="filter-item"
                          v-model="pagination.queryString"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建角色</el-button>
            </div>

            <el-table size="small" current-row-key="id" :data="list" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="name" label="角色名" align="center"></el-table-column>
                <el-table-column prop="keyword" label="角色关键词" align="center"></el-table-column>
                <el-table-column prop="description" label="角色描述" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">修改</el-button>
                        <el-button type="primary" size="mini" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>

            <div class="add-form">
                <el-dialog title="新增角色" :visible.sync="dialogFormVisible">
                    <el-tabs v-model="activeName" type="card">
                        <el-tab-pane label="基本信息" name="first">
                            <el-form ref="roleAddForm" :model="formData" label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="角色名称" prop="name">
                                            <el-input v-model="formData.name"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="角色关键字" prop="keyword">
                                            <el-input v-model="formData.keyword"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="22">
                                        <el-form-item label="角色描述" prop="description">
                                            <el-input type="textarea" v-model="formData.description"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                        </el-tab-pane>
                        <el-tab-pane label="权限信息" name="second">
                            <div class="checkScrol">
                                <table class="datatable">
                                    <thead>
                                    <tr>
                                        <th>选择</th>
                                        <th>权限名称</th>
                                        <th>关键词</th>
                                        <th>权限说明</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr v-for="permission in permissionList">
                                        <td>
                                            <input :id="permission.id" v-model="permissionIds" type="checkbox"
                                                   :value="permission.id">
                                        </td>
                                        <td><label :for="permission.id">{{permission.name}}</label></td>
                                        <td><label :for="permission.id">{{permission.keyword}}</label></td>
                                        <td><label :for="permission.id">{{permission.description}}</label></td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </el-tab-pane>
                        <el-tab-pane label="菜单信息" name="third">
                            <div class="checkScrol">
                                <table class="datatable">
                                    <thead>
                                    <tr>
                                        <th>选择</th>
                                        <th>角色名称</th>
                                        <th>关键词</th>
                                        <th>角色说明</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr v-for="menu in menuList">
                                        <td>
                                            <input :id="menu.id" v-model="menuIds" type="checkbox" :value="menu.id">
                                        </td>
                                        <td><label :for="menu.id">{{menu.name}}</label></td>
                                        <td><label :for="menu.id">{{menu.keyword}}</label></td>
                                        <td><label :for="menu.id">{{menu.description}}</label></td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </el-tab-pane>
                    </el-tabs>


                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <div class="add-form">
                <el-dialog title="编辑角色" :visible.sync="dialogFormVisible4Edit">
                    <el-tabs v-model="activeName" type="card">
                        <el-tab-pane label="基本信息" name="first">
                            <el-form ref="roleAddForm" :model="formData" label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="角色名称" prop="name">
                                            <el-input v-model="formData.name"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="角色关键字" prop="keyword">
                                            <el-input v-model="formData.keyword"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="22">
                                        <el-form-item label="角色描述" prop="description">
                                            <el-input type="textarea" v-model="formData.description"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                        </el-tab-pane>
                        <el-tab-pane label="权限信息" name="second">
                            <div class="checkScrol">
                                <table class="datatable">
                                    <thead>
                                    <tr>
                                        <th>选择</th>
                                        <th>权限名称</th>
                                        <th>关键词</th>
                                        <th>权限说明</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr v-for="permission in permissionList">
                                        <td>
                                            <input :id="permission.id" v-model="permissionIds" type="checkbox"
                                                   :value="permission.id">
                                        </td>
                                        <td><label :for="permission.id">{{permission.name}}</label></td>
                                        <td><label :for="permission.id">{{permission.keyword}}</label></td>
                                        <td><label :for="permission.id">{{permission.description}}</label></td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </el-tab-pane>
                        <el-tab-pane label="菜单信息" name="third">
                            <div class="checkScrol">
                                <table class="datatable">
                                    <thead>
                                    <tr>
                                        <th>选择</th>
                                        <th>角色名称</th>
                                        <th>关键词</th>
                                        <th>角色说明</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr v-for="menu in menuList">
                                        <td>
                                            <input :id="menu.id" v-model="menuIds" type="checkbox" :value="menu.id">
                                        </td>
                                        <td><label :for="menu.id">{{menu.name}}</label></td>
                                        <td><label :for="menu.id">{{menu.keyword}}</label></td>
                                        <td><label :for="menu.id">{{menu.description}}</label></td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </el-tab-pane>
                    </el-tabs>


                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            list: [],
            formData: [],
            dialogFormVisible: false,
            dialogFormVisible4Edit: false,
            dialogFormVisible4PermissionEdit: false,
            permissionList: [],//权限信息表
            permissionIds: [],
            menuList: [],//菜单信息表
            menuIds: [],
            activeName: "first"
        },
        created() {
            this.findPage();
        },
        methods: {
            //新增的时候查询所有数据
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible = true;
            },
            //新增确认
            handleAdd() {
                let url = " /role/add";
                axios.post(url, this.formData).then(response => {
                    //隐藏新增窗口
                    this.dialogFormVisible = false;
                    this.success(response.data.message);
                }).finally(() => {
                    this.findPage();//刷新页面
                });

            },
            //修改
            handleUpdate() {

            },
            //删除
            handleDelete(row) {
                //弹出确认框
                this.$confirm('你确定要删除当前数据吗？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //发送ajax请求，将id提交到Controller
                    let url = '/role/' + row.id;
                    axios.delete(url).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                type: 'success',
                                message: res.data.message
                            });
                            this.findPage();
                        } else {
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    })
                });
            },
            //编辑确认
            handleEdit(id) {
                this.dialogFormVisible4Edit = true;
            },
            findPage() {
                let url = " /role/findPage";
                //封装分页查询条件
                let param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                //发送ajax请求，进程分页查询
                axios.post(url, param).then((res) => {
                    this.list = res.data.rows;
                    this.pagination.total = res.data.total;
                });

            },
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;//指定最新的页码
                this.findPage();
            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },
        }
    })
</script>
</html>